When finding a matching non-scalable dir, keep going and look for a closer
authorMatthias Clasen <mclasen@redhat.com>
Mon, 15 Jan 2007 02:56:33 +0000 (02:56 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 15 Jan 2007 02:56:33 +0000 (02:56 +0000)
2007-01-14  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkicontheme.c (theme_lookup_icon): When finding a matching
        non-scalable dir, keep going and look for a closer match.
        (#395830, Luca Ferretti)

svn path=/trunk/; revision=17153

ChangeLog
gtk/gtkicontheme.c

index 4031574217480b4df7d7af22258e05f03f280b9d..54261d3f8d1241476936701c47b1b8047eed887d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-01-14  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkicontheme.c (theme_lookup_icon): When finding a matching
+       non-scalable dir, keep going and look for a closer match.
+       (#395830, Luca Ferretti)
+
 2007-01-14  Christian Persch  <chpe@svn.gnome.org>
 
        * gtk/gtkclipboard.c: (gtk_clipboard_set_text),
index 6cb06aeb7bc175f5a5506030ae17c5c1658e8e0d..2e404e788f4063938ece249c95e33fb58502e468 100644 (file)
@@ -1873,12 +1873,13 @@ theme_lookup_icon (IconTheme          *theme,
   char *file;
   int min_difference, difference;
   BuiltinIcon *closest_builtin = NULL;
-  gboolean smaller, has_larger;
+  gboolean smaller, has_larger, match;
   IconSuffix suffix;
 
   min_difference = G_MAXINT;
   min_dir = NULL;
   has_larger = FALSE;
+  match = FALSE;
 
   /* Builtin icons are logically part of the default theme and
    * are searched before other subdirectories of the default theme.
@@ -1912,31 +1913,55 @@ theme_lookup_icon (IconTheme          *theme,
 
          if (difference == 0)
            {
-             min_dir = dir;
-             break;
-           }
-
-         if (!has_larger)
-           {
-             if (difference < min_difference || smaller)
-               {
-                 min_difference = difference;
-                 min_dir = dir;
-                 closest_builtin = NULL;
-                 has_larger = smaller;
-               }
-           }
-         else
-           {
-             if (difference < min_difference && smaller)
-               {
-                 min_difference = difference;
-                 min_dir = dir;
-                 closest_builtin = NULL;
-               }
+              if (dir->type == ICON_THEME_DIR_SCALABLE)
+                {
+                  /* don't pick scalable if we already found
+                   * a matching non-scalable dir
+                   */
+                  if (!match)
+                    {
+                     min_dir = dir;
+                     break;
+                    }
+                }
+              else
+                {
+                  /* for a matching non-scalable dir keep
+                   * going and look for a closer match
+                   */             
+                  difference = abs (size - dir->size);
+                  if (!match || difference < min_difference)
+                    {
+                      match = TRUE;
+                      min_difference = difference;
+                     min_dir = dir;
+                    }
+                  if (difference == 0)
+                    break;
+                }
+           } 
+  
+          if (!match)
+            {
+             if (!has_larger)
+               {
+                 if (difference < min_difference || smaller)
+                   {
+                     min_difference = difference;
+                     min_dir = dir;
+                     has_larger = smaller;
+                   }
+               }
+             else
+               {
+                 if (difference < min_difference && smaller)
+                   {
+                     min_difference = difference;
+                     min_dir = dir;
+                   }
+               }
            }
-
-       }
+        }
 
       l = l->next;
 
@@ -1947,9 +1972,6 @@ theme_lookup_icon (IconTheme          *theme,
        }
     }
 
-  if (closest_builtin)
-    return icon_info_new_builtin (closest_builtin);
-  
   if (min_dir)
     {
       GtkIconInfo *icon_info = icon_info_new ();
@@ -2015,7 +2037,10 @@ theme_lookup_icon (IconTheme          *theme,
       
       return icon_info;
     }
+
+  if (closest_builtin)
+    return icon_info_new_builtin (closest_builtin);
+  
   return NULL;
 }